package com.xn.app.muying.adpter;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.bean.OrderDetailBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/12/1.
 */
public class OrderDetailAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context context;
    private ArrayList<OrderDetailBean> list = new ArrayList<>();
    private Handler handler = new Handler();

    public OrderDetailAdapter(Context context) {
        super();
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void getData(ArrayList<OrderDetailBean> data) {
        this.list.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.orderdetail_item, null);
            holder = new ViewHolder();
            holder.tv_ordernumber = (TextView) view.findViewById(R.id.ordernumber_tv);
            holder.tv_hosptial = (TextView) view.findViewById(R.id.hospitalname_tv);
            holder.tv_servicetype = (TextView) view.findViewById(R.id.servicetype_tv);
            holder.tv_servicecount = (TextView) view.findViewById(R.id.totalservicecount_tv);
            holder.tv_price = (TextView) view.findViewById(R.id.orderprice_tv);
            holder.tv_paymethod = (TextView) view.findViewById(R.id.paymethod_tv);
            holder.tv_time = (TextView) view.findViewById(R.id.paytime_tv);
            holder.tv_orderstatus = (TextView) view.findViewById(R.id.orderstatus_tv);
            holder.iv_hospitallogo = (ImageView) view.findViewById(R.id.hospitallogo_iv);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_ordernumber.setText("订单号：" + list.get(i).getOrderNumber());
        holder.tv_hosptial.setText(list.get(i).getHospitalName());
        if (list.get(i).getReceiveStatusId() != null && !list.get(i).getReceiveStatusId().equals("") && !list.get(i).getReceiveStatusId().equals("null")) {
            holder.tv_servicetype.setText("服务类型：" + list.get(i).getServiceProductName());
            holder.tv_servicecount.setText("设备领取：" + list.get(i).getReceiveStatusDescription());
        }else{
            holder.tv_servicetype.setText("服务类型：" + list.get(i).getServiceTypeDescription());
            holder.tv_servicecount.setText("服务次数：" + list.get(i).getTotalServiceCount()+"次");
        }
        holder.tv_paymethod.setText("支付方式：" + list.get(i).getPayMethodDescription());
        holder.tv_price.setText("-" + list.get(i).getOrderPrice());
        String[] strs = list.get(i).getCreationTime().split("T");
        String[] strs2 = strs[1].split(":");
        holder.tv_time.setText("下单时间：" + strs[0] + " " + strs2[0] + ":" + strs2[1]);

        holder.tv_orderstatus.setText(list.get(i).getPaymentStatusDescription());
        holder.iv_hospitallogo.setTag(list.get(i).getHospitalLogo());
//        HttpUtil.getBitMap(list.get(i).getHospitalLogo(),handler, holder.iv_hospitallogo);
        return view;
    }

    class ViewHolder {
        TextView tv_ordernumber, tv_hosptial, tv_servicetype, tv_servicecount, tv_price, tv_paymethod, tv_time, tv_orderstatus;
        ImageView iv_hospitallogo;
    }
}
